<?php

namespace App\Http\Controllers\Manage;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\QualityControlManage;
use Illuminate\Http\Request;
//品控管理
class QualityControlController extends Controller
{
    use ResponseData;
    public function list(QualityControlManage $model,Request $request){
        $size = $request->input('size',10);
        if($request->filled('start')&&$request->filled('end')){
            $model = $model->whereBetween('created_at',[$request->start,$request->end]);
        }
        if($request->filled('cutomer_name')){
            $model = $model->where('contact_name','like','%'.$request->cutomer_name.'%');
        }
        if($request->filled('system_user')){
            $model = $model->where('system_user_name','like','%'.$request->system_user.'%');
        }
        if($request->filled('status')&&$request->status=='all'){
            $data = $model->orderBy('id','desc')->get();
        }else{
            $data = $model->orderBy('id','desc')->paginate($size);
        }
        return $this->success($data);
    }
    public function store(QualityControlManage $model,Request $request){
        $data = $request->all();
        $model->fill($data);
        $model->save();
        return $this->success('保存成功');
    }
    public function edit(QualityControlManage $model,Request $request){
        $data = $model->find($request->id);
        return $this->success($data);
    }
    public function update(QualityControlManage $model,Request $request){
        $data = $model->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(QualityControlManage $model,Request $request){
        $data = $model->find($request->id);
        $data->delete();
    }
}
